#include<bits/stdc++.h>//P30
using namespace std;
priority_queue<int,vector<int>,greater<int>>q;//定义堆
int main(){
    int n;scanf("%d",&n);
    while(n--){
        int op;scanf("%d",&op);
        if(op==1){int x;scanf("%d",&x);q.push(x);}//进堆
        else if(op==2)printf("%d\n",q.top());
        else q.pop();
    }
    return 0;
}